package edu.tms.dao;

import java.util.List;
import java.util.Map;

import edu.tms.bean.Permission;
import edu.tms.crud.JdbcUtil;
import edu.tms.dao.common.CommnonDao;

/**
 * 权限dao
 * @author Administrator
 *
 */
@SuppressWarnings("rawtypes")
public class PermissionDaoImp  implements CommnonDao{
	/**
	 * 保存内容
	 * @param value
	 * @return 
	 * @throws Exception
	 */
	@Override
	public long save(Object value) throws Exception {
		//判断类   instanceof 
		Permission per=null;
		if(value instanceof Permission){
			per=(Permission)value;
			String sql="INSERT INTO t_permission(permission_name,permission_info,permission_state)VALUES(?,?,?)";
			long Number=JdbcUtil.insertAuto(sql,
					per.getPermissionName(),
					per.getPermissionInfo(),
					per.getPermissionState()
					);
			return Number;
		}
		return 0;
	}
	/**
	 * 修改内容
	 * @param value
	 * @throws Exception
	 */
	@Override
	public int update(Object value) throws Exception {
		//判断类   instanceof 
		Permission per=null;
		if(value instanceof Permission){
			per=(Permission)value;
			String sql="UPDATE t_permission SET permission_info=?,permission_state=? WHERE permission_id=?";
			int Number=JdbcUtil.update(sql,
					per.getPermissionInfo(),
					per.getPermissionState(),
					per.getPermissionId());
			return Number;
		}
		return 0;
	}
	
	/**
	 * 删除内容
	 * 学生表 t_student
	 * @param value
	 * @throws Exception
	 */
	@Override
	public int delete(Object value) throws Exception {
		// TODO Auto-generated method stub
		return 0;
	}
	/**
	 * 查找所有的内容
	 * @param pageNo 第几页
	 * @param pageSize 每页数字
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Permission> findAll(int pageNo, int pageSize) throws Exception {
		String sql="SELECT * FROM t_permission limit ?,?";
		return JdbcUtil.query(Permission.class,sql,(pageNo-1)*pageSize,pageSize);
	}
	

	/**
	 * String 对应  数据库 列名（comment)
	 * Object 对应相应列名值
	 * 返回的是所查找的类中的数据。方便EXCEL导出
	 */
	@Override
	public List<Map<String,Object>> getMapList() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Permission> findAll(Object key, int pageNo, int pageSize) throws Exception {
		String sql="SELECT * FROM t_permission where permission_id=? OR permission_name=? OR permission_info=? limit ?,? ";
		return JdbcUtil.query(Permission.class,sql,key,key,key,(pageNo-1)*pageSize,pageSize);
	}
	@Override
	public Object findByKey(Object key) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
